import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ConfirmationService } from 'primeng';
import { DWD_DOWNLOAD_URL } from 'src/app/common-url';

@Component({
  selector: 'app-soft-pic',
  templateUrl: './soft-pic.component.html',
  styleUrls: ['./soft-pic.component.scss']
})
export class SoftPicComponent implements OnInit {

  public articleList: Array<any>; // 文章数组
  public currentArticle: any; // 当前软件对象
  public articleShow: boolean; // 是否显示列表
  constructor(
    public http: HttpClient,
    public confirmationService: ConfirmationService) {
    this.articleList = [];
  }

  ngOnInit(): void {
    this.getList();
  }

  public getList() {
    const req = {
      type: '2'
    };
    this.sendPost(DWD_DOWNLOAD_URL.articleTableList, req).subscribe((res: any) => {
      if (!res.status) {
        this.confirmationService.confirm({
          header: '错误提示',
          message: '出现未知异常',
          acceptLabel: '确定',
          rejectLabel: '取消'
        });
      } else {
        this.articleList = res.data;
      }
    });
  }

  public softwareHandle(item, event) {
    this.currentArticle = item;
  }

  public sendPost(url, req) {
    return this.http.post(url, req);
  }

  public contentDecode(content) {
    return unescape(content);
  }
}
